from ckeditor_uploader.fields import RichTextUploadingField
from django.db.models import SET_NULL

from accounts.models import *
from workflows.models import *


class File(UpTime):
    objects = None
    owner = models.OneToOneField('auth.User', on_delete=models.CASCADE, verbose_name="文件所属")
    file = models.FileField(upload_to='file/%Y/%m/%d', null=True, blank=True, help_text='上传文件',
                            verbose_name='文件')

    class Meta:
        db_table = 'File'
        verbose_name = '用户文件'
        verbose_name_plural = verbose_name

    """后台显示名称"""

    def __str__(self):
        return self.owner


class Article(UpTime):
    objects = None
    title = models.CharField(verbose_name='标题', max_length=32, blank=True, help_text='标题')
    content = RichTextUploadingField(verbose_name='正文')
    picture = models.ImageField(upload_to='text/%Y/%m/%d', null=True, blank=True)
    owner = models.OneToOneField('auth.User', on_delete=models.CASCADE, null=True, blank=True, verbose_name='作者')
    ascription = models.ForeignKey('accounts.Dept', on_delete=models.CASCADE, verbose_name='文章所属', blank=True,
                                   null=True)
    status = models.ForeignKey('workflows.State', verbose_name="状态", null=True, blank=True, on_delete=models.DO_NOTHING,
                               help_text="状态")
    auditing = models.CharField(verbose_name='审核人', max_length=32, default=0)

    class Meta:
        db_table = 'Article'
        verbose_name = '用户文章'
        verbose_name_plural = verbose_name

    """后台显示名称"""

    def __str__(self):
        return self.title
